# Author    :Dun_Hz
# Time      :2024/3/16 20:40
# 循环赛，n个选手之间比赛，偶数n-1天，奇数n天（轮空）
import numpy as np
m = 0
def competition(n, mymat):
    if n==2:
        mymat[0,0]=1
        mymat[0,1]=2
        mymat[1,0]=2
        mymat[1,1]=1
        return
    if n%2 ==1:
        t = int((n+1)/2)
        n += 1
    else:
        t =int(n/2)
    competition(t, mymat)
    global m
    m +=1
    print(m)
    print(n)
    if n%4==0:
        for i in range(int(n/2)):
            for j in range(int(n/2)):
                thevalue = mymat[i][j]
                mymat[i+t][j]=thevalue+t
                mymat[i][j+t]=thevalue+t
                mymat[i+t][j+t]=thevalue
                print(mymat)
    else:
        for i in range(int(n/2)):
            for j in range(int(n/2)+1):
                thevalue = mymat[i][j]
                if thevalue > t:
                    mymat[i+t][j]=i+1
                    mymat[i][j]=i+t+1
                    c = i+t+2
                    k = int(n/2)+1
                    while k < n:
                        if c>n:
                            c-=t
                        mymat[i][k]=c
                        mymat[c-1][k]=i+1
                        c+=1
                        k+=1
                else:
                    mymat[i+t][j]=thevalue+t
                print(mymat)
    return mymat

def main():
    a = int(input('输入人数：'))
    if a %2 ==0:
        b = np.zeros([a,a])
        competition(a,b)
    else:
        b = np.zeros([a+1,a+1])
        competition(a+1,b)
        for i in range(a+1):
            for j in range(a+1):
                if b[i][j]>a:
                    b[i][j]=0
                if i == a:
                    b[i][j]=0
    print(b)

if __name__=='__main__':
    main()